package com.itheima;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

public class Demo2 {
    public static void main(String[] args) {
        Student st1 = new Student("张三","男",20,79.5);
        Student st2 = new Student("李四","女",21,80.2);
        Student st3 = new Student("王五","男",22,77.9);
        Student st4 = new Student("周六","男",20,55.8);
        Student st5 = new Student("赵七","女",21,99.9);

        List<Student> sts = new ArrayList<>();
        sts.add(st1);
        sts.add(st2);
        sts.add(st3);
        sts.add(st4);
        sts.add(st5);
        BigDecimal sumScore = new BigDecimal(0.0);
        for (Student stu: sts) {
            BigDecimal bd = new BigDecimal(stu.getScore());
            sumScore=sumScore.add(bd);
        }
        BigDecimal divNum = new BigDecimal(sts.size());
        BigDecimal avgScore =sumScore.divide(divNum, 2, RoundingMode.HALF_UP);
        System.out.println("总分为："+sumScore.doubleValue());
        System.out.println("5名学员的“平均分”(四舍五入到小数点后2位)："+avgScore.doubleValue());
    }
}
